package cn.imu.appdevexperiment2020.Application.api;

import android.content.Context;

import java.util.Map;

import cn.imu.appdevexperiment2020.Application.bean.ClassBean;
import cn.imu.appdevexperiment2020.Application.bean.ClassListBean;
import cn.imu.appdevexperiment2020.Application.bean.user.EditReceiveBean;
import cn.imu.appdevexperiment2020.Application.bean.user.EditSendBean;
import cn.imu.appdevexperiment2020.Application.bean.user.UserBean;
import cn.imu.appdevexperiment2020.Application.bean.user.UserListBean;
import cn.imu.appdevexperiment2020.Application.bean.user.LoginReceiveBean;
import cn.imu.appdevexperiment2020.Application.bean.user.LoginSendBean;
import cn.imu.appdevexperiment2020.Application.bean.user.RegisterReceiveBean;
import cn.imu.appdevexperiment2020.Application.bean.user.RegisterSendBean;
import cn.imu.appdevexperiment2020.Application.bean.user.ResetPwdReceiveBean;
import cn.imu.appdevexperiment2020.Application.bean.user.ResetPwdSendBean;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiClient {
    private Retrofit mRetrofit;
    private Api mApi;
    private static ApiClient sApiClient;
    private ApiClient(final Context context){
        mRetrofit=new Retrofit.Builder().baseUrl(GetApi.baseURL).addConverterFactory(GsonConverterFactory.create()).build();
        mApi =mRetrofit.create(Api.class);
    }
    public static ApiClient getInstance(Context context){
        if(sApiClient==null)
            sApiClient=new ApiClient(context);
        return sApiClient;
    }
    public static void destoryInstance(){
        if(sApiClient!=null)
            sApiClient=null;
    }
    public String getRootURL() {
        return GetApi.baseURL;
    }
    public Call<RegisterReceiveBean> getReturnData(Map<String,String>map, RegisterSendBean registerSendBean){
        return mApi.register(map,registerSendBean);
    }
    public Call<LoginReceiveBean> getReturnData(Map<String,String>map, LoginSendBean loginSendBean){
        return mApi.login(map,loginSendBean);
    }
    public Call<ResetPwdReceiveBean> getReturnData(Map<String,String>map, ResetPwdSendBean resetPwdSendBean){
        return mApi.resetPwd(map,resetPwdSendBean);
    }
    public Call<EditReceiveBean> getReturnData(Map<String,String>map, EditSendBean editSendBean){
        return mApi.edit(map,editSendBean);
    }
    public Call<UserListBean> getReturnData(Map<String,String>map, String sex, int classesId){
        return mApi.list(map,sex,classesId);
    }
    public Call<UserBean> getReturnData(Map<String,String>map, String userName){
        return mApi.getByUserName(map,userName);
    }
    public Call<UserBean> getReturnData1(Map<String,String>map, String userId){
        return mApi.getById(map,userId);
    }
    public Call<ClassListBean> getReturnData(Map<String,String>map, String parentId,String leader){
        return mApi.classeslist(map,parentId,leader);
    }
    public Call<ClassBean> getReturnData2(Map<String,String>map, String classesId){
        return mApi.getClasses(map,classesId);
    }
}
